<template>
  <div>
    <!-- 这里要记住不能v-for绑定el-row -->
    <div v-for="(item, index) in lands" :key="item.landId" class="land">
      <!-- 第一条信息 -->
      <el-row>
        <!-- 土地部分 -->
        <el-col :span="6" class="landName">
          <img :src="item.landPic" class="landPic" />
          <span>{{ item.landName }}</span>
        </el-col>
        <!-- 文字部分  -->
        <el-col :span="6" class="text2">
          <h1>位置:{{ item.position }}</h1>
        </el-col>
      </el-row>
    </div>
    <!-- 新的土地 -->
    <div class="newLand">
      <h1>没有更多土地了</h1>
      <el-button text @click="dialogVisibleLand = true"> 新的土地 </el-button>
    </div>
    <!-- 新的土地 -->
    <!-- 增加土地部分 -->
    <el-dialog
      v-model="dialogVisibleLand"
      width="32%"
      :before-close="handleClose"
      style="background-color: #a3ea9b"
    >
      <div class="inNewland">
        <h1 class="title">为您注册新的土地</h1>
        <h1>农作品种类</h1>
        <el-select
          v-model="plant"
          clearable
          placeholder="选择类型"
          style="width: 240px"
        >
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <h1>土地位置</h1>
        <el-select
          v-model="position"
          clearable
          placeholder="选择位置"
          style="width: 240px"
        >
          <el-option
            v-for="item in options2"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <div>
          <el-button @click="addLand()"> 确定 </el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { ref } from "vue";
import axios from "axios";
import { ElMessage } from "element-plus";

export default {
  name: "",
  components: {},
  data() {
    return {
      dialogVisibleLand: ref(false),
      showStatusBar: false,
      drawStatus: true,
      show: ref(true),
      plant: ref(""),
      position: ref(""),
      lands: [
        {
          landId: "",
          landName: "土地A",
          landPic: require("@/assets/backgroundImage.png"),
          position: "田间",
        },
        {
          landId: "",
          landName: "土地B",
          landPic: require("@/assets/backgroundImage.png"),
          position: "山里",
        },
      ],
      options1: [
        {
          value: "土豆",
          label: "土豆",
        },
        {
          value: "小麦",
          label: "小麦",
        },
        {
          value: "红薯",
          label: "红薯",
        },
        {
          value: "萝卜",
          label: "萝卜",
        },
        {
          value: "白菜",
          label: "白菜",
        },
        {
          value: "苹果",
          label: "苹果",
        },
        {
          value: "西红柿",
          label: "西红柿",
        },
        {
          value: "梨子",
          label: "梨子",
        },
        {
          value: "玉米",
          label: "玉米",
        },
        {
          value: "大豆",
          label: "大豆",
        },
      ],
      options2: [
        {
          value: "东区1号",
          label: "东区1号",
        },
        {
          value: "东区2号",
          label: "东区2号",
        },
        {
          value: "东区3号",
          label: "东区3号",
        },
        {
          value: "西区1号",
          label: "西区1号",
        },
        {
          value: "西区2号",
          label: "西区2号",
        },
        {
          value: "西区3号",
          label: "西区3号",
        },
      ],
    };
  },
  methods: {
    addLand() {
      if (this.plant != "" && this.position != "") {
        const land = {};
        land.landName = "土地C";
        land.landPic = require("@/assets/backgroundImage.png");
        land.position = this.position;
        land.plant = this.plant;
        // console.log(land.join(","));
        this.lands.push(land);
        this.plant = "";
        this.position = "";
        ElMessage({
          message: "添加成功！",
          type: "success",
        });
      } else {
        if (this.plant == "") {
          ElMessage({
            message: "请选农作物类型！",
            type: "error",
          });
        }
        if (this.position == "") {
          ElMessage({
            message: "请选择土地位置！",
            type: "error",
          });
        }
      }
    },
  },
  //从后端接口获取数据
  created() {
    // this.getData();
    // this.setStatus();
  },
  mounted() {},
};
</script>

<style lang="css" scoped>
.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: red;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}

/* 土地部分 */
.land {
  border: solid 0.5px rgb(0, 0, 0);
  background-color:  transparent;
  /* #67b383 */
  border-collapse: collapse;
}

.landName {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin-left: 5px;
}

.landName span {
  padding-left: 20px;
}

.landPic {
  height: 100px;
  width: 150px;
  margin: 10px 0 10px 10px;
  /* margin: 20px 0 0 190px; */
}

/* 文字部分 */
.text2 h1 {
  padding-left: 15px;
  font-size: 25px;
  font-weight: normal;
  margin-block-start: 0;
  margin-block-end: 0;
}

.text1 {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}

.text2 {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  margin: auto 0 auto 10px;
}

/* 创建新的土地部分 */
.newLand {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
  font-size: 30px;
}

.newLand h1 {
  font-weight: 100;
}

.newLand .el-button {
  background-color: #4bc05d;
  color: white;
  width: 150px;
  height: 50px;
  margin-left: 10px;
  font-size: 20px;
}

/* 创建新的土地部分浮窗 */
.inNewland {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  color: white;
}

.inNewland .title {
  font-size: 25px;
}

.inNewland h1 {
  margin: 10px 0;
  font-weight: 100;
  font-size: 30px;
}

.inNewland .el-button {
  background-color: #4bbf5c;
  color: white;
  height: 70px;
  width: 200px;
  margin-top: 10px;
  font-size: 45px;
  font-weight: 100;
}
</style>
